<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<title>登录</title>
<link href="style/login.css" rel="stylesheet" type="text/css" />
<link href="css/vant.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="login_boss/js/js.js"></script>
<script src="js/vue/vue.js"></script>
<script src="js/vue/axios.js"></script>
<script src="js/vue/qs.js"></script>
<script src="js/vue/MD5.js"></script>
<script src="js/vue/vant.js"></script>
</head>
<body>
<div id="app">
    <div v-show="isShow">
        <div class="ve_title"><span>{{titles}}</span></div>
        <div class="main">
            <div class="login_txt">登录</div>
            <div class="login_type_o">
                <span style="background-image:url(images/phones.png); color:#0092fd" id="ck_phone" onclick="check_login('phone')">短信登录</span>
                <span style="background-image:url(images/user.png)" id="ck_user"  onclick="check_login('user')">密码登录</span>
            </div>
            <input ref="login_type" id="login_type" type="hidden" value="phone" />
            <input ref="send" id="send" type="hidden" value="60" />
            <div class="login_o" id="phone_login">
                <div class="login_text">手机号</div>
                <div class="login_input">
                    <input v-model="from1.phone" style="font-size: 14px;" id="phone" type="text" class="phone_input" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="11" onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入手机号码"/>
                </div>
                <div class="login_text" style="margin-top:10px">短信验证码</div>
                    <div class="login_input_code"  style="padding-bottom:3px;">
                    <input v-model="from1.sms_code" style="font-size: 14px;width: 50%;" id="code" type="text" class="code_input" placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="6" onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width:55%;"/>
                    <div class="code_getcode" @click="get_sms_code()" style="float:right;">获取验证码</div>
                </div>
            </div>
            <div class="login_o" id="user_login" style="display:none">
                <div class="login_text">手机号</div>
                <div class="login_input">
                    <input v-model="from.username"
                     style="font-size: 14px;" id="uphone" 
                     type="text" class="phone_input" 
                     onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入手机号码"/>
                </div>
                <div class="login_text" style="margin-top:10px">密码</div>
                <div class="login_input_code"  style="padding-bottom:3px;">
                    <input v-model="from.password" style="font-size: 14px;" id="upassword" type="password" class="code_input" placeholder="请输入验密码"/>
                </div> 
                    <a href="login_set.html" class="login_text" style="margin-top:10px; font-size:13px; text-align:right;"> 设置密码</a>
            </div>
            <div class="login_but_o" @click="gologins()">登录</div>
            <!-- <div class="wxlogin"><img src="images/wx2.png" @click="wxlogin"/></div>	 -->
        </div>
    </div>
    <div v-show="!isShow" class="main">
        <div class="ve_title">请先绑定手机号码</div>
        <div class="login_o" id="phone_login">
            <div class="login_text">手机号</div>
            <div class="login_input">
                <input v-model="from1.phone" style="font-size: 14px;" id="phone" type="text" class="phone_input" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="11" onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入手机号码"/>
            </div>
            <div class="login_text" style="margin-top:10px">短信验证码</div>
                <div class="login_input_code"  style="padding-bottom:3px;">
                <input v-model="from1.sms_code" style="font-size: 14px;width: 50%;" id="code" type="text" class="code_input" placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="6" onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width:55%;"/>
                <div class="code_getcode" @click="get_sms_code()" style="float:right;">获取验证码</div>
            </div>
        </div>
        <div class="login_but_o" @click="bingPhone">绑定手机号</div>
    </div>
</div>
</body>
<script>
var app = new Vue({
    el: '#app',
    data: {
        sending:false,
        sendData: {},
        isShow:true,
        vid:'',
        titles:'',
        helloData: {},
        from:{
            username: '',
            password: '',
            vid:'',
            action:"boss"
        },
        from1:{
            sms_code: "",
            phone: "",
            vid:'',
            action:"boss"
        },
        wxinfo:'',
        Openid:'',
        Unionid:'',
        VidPhone:'',
        state:''
    },
    created(){
        this.setCanS()
    },
    methods: {
        //设置参数
        setCanS(){
            //获取登录状态
            let timeLoc=new Date()
            let isBeOverdue=Date.parse(localStorage.getItem('bossTime'))
            console.log(Date.parse(isBeOverdue))
            console.log(timeLoc.getTime())
            console.log(timeLoc.getTime()-Date.parse(isBeOverdue))
            let Request = new Object()
            Request = GetRequest()
            this.vid = Request['vid']
            this.wxinfo = Request['wxinfo']
            if(this.vid==undefined||this.vid==''||this.vid=='null'){
                this.vid=''
            }else{
                sessionStorage.setItem('vid',this.vid)
            }
            this.from.vid=this.vid
            this.from1.vid=this.vid
            this.getSname()
            if(this.wxinfo!=''&&this.wxinfo!=null&&this.wxinfo!=undefined){
                this.getWxlogin()
            }
            console.log(this.vid)
            if(this.vid==''){
                //判断是否过期
                if(isBeOverdue!=undefined&&isBeOverdue!=''&&isBeOverdue!=null&&isNaN(isBeOverdue)!=true){
					//判断是否过期
					if(timeLoc.getTime()-isBeOverdue>0){
						//过期
					}else{
						//未过期
						let vid=localStorage.getItem('bossvid')
						let Gtoken=localStorage.getItem('bossGtoken')
						sessionStorage.setItem('logo','0')
						sessionStorage.setItem('token',Gtoken)
						sessionStorage.setItem('vid',vid)
						let type="logo"
						sessionStorage.setItem('type',type)
						window.location.href='index.html?vid='+vid+'&type='+type+''
					}
				}
            }else{
                if(isBeOverdue!='null'&&isBeOverdue!=undefined&&isBeOverdue!=''&&isNaN(isBeOverdue)!=true){
                    //判断vid是否想同
                    let vid=localStorage.getItem('bossvid')
                    if(this.vid!=vid){

                    }else{
                         //判断是否过期
                        if(timeLoc.getTime()-isBeOverdue>0){
                            //过期
                            
                        }else{
                            //未过期
                            let vid=localStorage.getItem('bossvid')
                            let Gtoken=localStorage.getItem('bossGtoken')
                            sessionStorage.setItem('logo','0')
                            sessionStorage.setItem('token',Gtoken)
                            sessionStorage.setItem('vid',vid)
                            let type="logo"
                            sessionStorage.setItem('type',type)
                            window.location.href='index.html?vid='+vid+'&type='+type+''
                        }
                    }
                }
            }
        },
            //设置参数
            // setCanS(){
            //     let Request = new Object()
            //     Request = GetRequest()
            //     this.vid = Request['vid']
            //     this.wxinfo = Request['wxinfo']
            //     this.state = Request['state']
            //     //获取场馆名称
            //     if(this.vid==undefined&&this.vid==''&&this.vid==null){
            //         this.vid=''
            //     }else{
            //         sessionStorage.setItem('vid',this.vid)
            //     }
            //     if(this.state==undefined||this.state==''||this.state==null){
            //         this.state=''
            //     }else{
            //         sessionStorage.setItem('vid',this.state)
            //     }
            //     const params={
            //         vid:sessionStorage.getItem('vid')
            //     }
            //     sessionStorage.setItem('logo','1')
            //     axios.get('/mobileapi/login_staff.php?act=login',{params:params}).then(data =>{
            //         //console.log(data.data)
            //         let { msg, code} = data.data
            //             if (code != 200) {
            //                 window.vant.Toast.fail(msg)
            //             } else {
            //                  data = data.data
            //                  this.titles=data.data.Vname
            //             }
                        
            //         }).catch(function (error) { 
            //             console.log(error); 
            //     });
            //     this.from.vid=this.vid
            //     this.from1.vid=this.vid
            //     if(this.wxinfo!=''&&this.wxinfo!=null&&this.wxinfo!=undefined){
            //         this.getWxlogin()
            //     }
            // },
            //获取场馆名称
            getSname(){
                const params={
                    vid:this.vid
                }
                sessionStorage.setItem('logo','1')
                axios.get('/mobileapi/member/login.php?act=login',{params:params}).then(data =>{
                    console.log(data.data)
                    let { msg, code} = data.data
                        if (code !== 200) {
                            window.vant.Toast.fail(msg)
                        } else {
                            data = data.data.data
                            this.titles=data.Vname
                            console.log(this.titles)
                        }
                        
                    }).catch(function (error) { 
                        console.log(error); 
                });
            },
            //登录
            gologins() {
                sessionStorage.setItem('logo','1')
                if(this.$refs.login_type.value=='user'){
                    var obj = this;
                    let password=md5(this.from.password)
                    password=md5(password)
                    console.log(password)
                    let from = { 
                         username: this.from.username,
                         password: password,
                         vid:sessionStorage.getItem('vid'),
                         action:"boss"};
                    from =JSON.stringify(from)
                    let sign=md5(from)
                    let params={
                        from:from,
                        sign:sign
                    }
                    axios.post('/mobileapi/login_staff.php?act=logingo',
                    Qs.stringify(params)).then(function(response){
                        let { msg, code} = response.data
                            if (code !== 200) {
                                window.vant.Toast.fail(msg)
                            } else {
                                var data = response.data
                                console.log(data)
                                sessionStorage.setItem('vxPhone',data.data.Phone)
                                if(data.data.login_from=='BOSS'){
                                    if(data.data.login_type=='2'){
                                        sessionStorage.setItem('logo','1')
                                        sessionStorage.setItem('token',data.data.Gtoken)
                                        let venueset_list=JSON.stringify(data.data.venueset_list)
                                        sessionStorage.setItem("venueset_list",venueset_list)
                                        //跳转到选择场馆页面
                                        window.location.href='selectShop.html?vid='+this.vid+''
                                    }else{
                                        sessionStorage.setItem('logo','0')
                                        sessionStorage.setItem('token',data.data.Gtoken)
                                        console.log(data.data.Vid)
                                        this.vid=data.data.Vid
                                        sessionStorage.setItem('vids',this.vid)
                                        sessionStorage.setItem('vid',this.vid)
                                        let type="logo"
                                        localStorage.setItem('boss',"1")
                                        localStorage.setItem('bossvid',data.data.Vid)
                                        localStorage.setItem('bossGtoken',data.data.Gtoken)
                                        //保存登录有效期
                                        let timeLoc=new Date()
                                        localStorage.setItem('bossTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))
                                        sessionStorage.setItem('type',type)
                                        window.location.href='index.html?vid='+this.vid+'&type='+type+''
                                    }
                                }else{
                                    window.vant.Toast("该账号无法登陆BOSS端")
                                }
                                
                            }
                        }).catch(function (error) { 
                            console.log(error); 
                    });
                }else{
                    this.from1.vid=sessionStorage.getItem('vid')
                    let from = this.from1;
                    from["data"] = this.sendData;

                    from =JSON.stringify(from)
                    let sign=md5(from)
                    let params={
                        from:from,
                        sign:sign
                    }
                    axios.post('/mobileapi/login_staff.php?act=sms_login',Qs.stringify(params)).then(data => {
                        let { msg, code} = data.data
                            if (code !== 200) {
                                window.vant.Toast.fail(msg)
                            } else {
                                var data = data.data
                                if(data.data.login_from=='BOSS'){
                                    if(data.data.login_type=='2'){
                                        sessionStorage.setItem('logo','1')
                                        sessionStorage.setItem('token',data.data.Gtoken)
                                        let venueset_list=JSON.stringify(data.data.venueset_list)
                                        sessionStorage.setItem("venueset_list",venueset_list)
										sessionStorage.setItem('vxPhone',this.from1.phone)
                                        //跳转到选择场馆页面
                                        window.location.href='selectShop.html?vid='+this.vid+''
                                    }else{
                                        sessionStorage.setItem('logo','0')
                                        sessionStorage.setItem('token',data.data.Gtoken)
                                        console.log(data.data.Vid)
                                        this.vid=data.data.Vid
                                        sessionStorage.setItem('vids',this.vid)
                                        sessionStorage.setItem('vid',this.vid)
                                        let type="logo"
                                        localStorage.setItem('boss',"1")
                                        localStorage.setItem('bossvid',data.data.Vid)
                                        localStorage.setItem('bossGtoken',data.data.Gtoken)
                                        //保存登录有效期
                                        let timeLoc=new Date()
                                        localStorage.setItem('bossTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))
                                        sessionStorage.setItem('type',type)
                                        window.location.href='index.html?vid='+this.vid+'&type='+type+''
                                    }
                                }else{
                                    window.vant.Toast("该账号无法登陆BOSS端")
                             }
                            }
                        }).catch(function (error) { 
                            console.log(error); 
                    });
                }
            },
            //获取手机验证码
            get_sms_code(){
                var send=parseInt(this.$refs.send.value);
                if(!isPoneAvailable(this.from1.phone)){
                    window.vant.Toast.fail("请输入正确的手机号")
                    return false;
                }
                const params={
                    phone:this.from1.phone
                }
                if (this.sending) {
                    return;
                }
                if(send==60){
                    this.sending = true;
                    var that = this;

                    axios.post('/mobileapi/member/login.php?act=getsms',Qs.stringify(params)).then(function(response){
                            if(response.data.code=="200"){
                                that.sendData = response.data.data;
                            console.log(that.sendData);
								window.vant.Toast.success("短信已发，请注意查收")
							}else{
								window.vant.Toast.fail(response.data.msg)
							}
                        }).catch(function (error) {
                            that.sending = false;
                            console.log(error)
                            window.vant.Toast.fail("短信发送失败！请确认手机号是否正确。");
                    })   
                    var set=setInterval(function(){
                        var send_t=--send;
                        $(".code_getcode").html(""+send_t+"秒");
                        $("#send").val(--send_t)
                    }, 1000);
                    setTimeout(function(){
                        that.sending = false;
                        $(".code_getcode").html("重新获取");
                        $("#send").val(60)
                        clearInterval(set);
                    }, 60000);
                }	
            },
            //验证手机号正不争取
            isPoneAvailable($poneInput) {
                var myreg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;
                if (!myreg.test($poneInput)) {
                    return false;
                } else {
                    return true;
                }
            },
            //微信登录
            wxlogin(){
                window.location.href='http://wx.bj.guanjialc.com/api/wxlogin.php?Assystem=3fc62b5aec87be2e4dd05a531412cc4f&Venid='+this.vid+'&backurl=http%3a%2f%2ffitness.guanjialc.com%2fphone%2fboss%2flogin.html%3fvid='+this.vid+''
            },
            //获取code然后跳去接口登录
            getWxlogin(){
                sessionStorage.setItem('logo','1')
                let params={
                    vid:sessionStorage.getItem('vid'),
                    wxinfo:this.wxinfo,
                    action:"boss"
                }
                axios.get('/mobileapi/login_staff_wx_b.php?act=login',
                {params:params}).then(data => {
                    console.log(data.data)
                    let { msg, code} = data.data
                        if (code !== 200) {
                            window.vant.Toast.fail(msg)
                        } else {
                            data = data.data
                            if(data.data.login_from=="BOSS"){
                                if(data.data.login_type=='2'){
                                    sessionStorage.setItem('logo','1')
                                    sessionStorage.setItem('token',data.data.Gtoken)
                                    let venueset_list=JSON.stringify(data.data.venueset_list)
                                    sessionStorage.setItem("venueset_list",venueset_list)
                                    //跳转到选择场馆页面
                                    window.location.href='selectShop.html?vid='+this.vid+''
                                }else if(data.data.login_type=='1'){
                                    sessionStorage.setItem('logo','0')
                                    sessionStorage.setItem('token',data.data.Gtoken)
                                    this.vid=data.data.Vid
                                    sessionStorage.setItem('vids',this.vid)
                                    sessionStorage.setItem('vid',this.vid)
                                    let type="logo"
                                    localStorage.setItem('boss',"1")
                                    localStorage.setItem('bossvid',data.data.Vid)
                                    localStorage.setItem('bossGtoken',data.data.Gtoken)
                                    //保存登录有效期
                                    let timeLoc=new Date()
                                    localStorage.setItem('bossTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))
                                    sessionStorage.setItem('type',type)
                                    window.location.href='index.html?vid='+this.vid+'&type='+type+''
                                }else{
                                    //绑定手机号弹出手机号和验证码
                                    this.Openid=data.data.Openid
                                    if(data.data.Unionid){
                                        this.Unionid=data.data.Unionid
                                    }else{
                                        this.Unionid=''
                                    }
                                    this.VidPhone=data.data.Vid
                                    this.isShow=false
                                }
                            }else{
                                window.vant.Toast("该账号无法登陆BOSS端")
                            }
                        }
                    }).catch(function (error) { 
                        console.log(error); 
                });
            },
            //绑定手机号跳转首页
            bingPhone(){
                let from = {
                        phone:this.from1.phone,
                        sms_code: this.from1.sms_code,
                        vid:this.VidPhone,
                        login_from:"BOSS",
                        openid:this.Openid,
                        unionid:this.Unionid
                     }
                from =JSON.stringify(from)
                let sign=md5(from)
                let params={
                    from:from,
                    sign:sign
                }
                axios.post('/mobileapi/login_staff_wx_b.php?act=bing_phone',
                    Qs.stringify(params)).then(data => {
                    let { msg, code} = data.data
                        if (code !== 200) {
                            window.vant.Toast.fail(msg)
                        } else {
                            data = data.data
                            if(data.data.login_from=='BOSS'){
                                if(data.data.login_type=='2'){
                                    sessionStorage.setItem('logo','1')
                                    sessionStorage.setItem('token',data.data.Gtoken)
                                    let venueset_list=JSON.stringify(data.data.venueset_list)
                                    sessionStorage.setItem("venueset_list",venueset_list)
                                    //跳转到选择场馆页面
                                    window.location.href='selectShop.html?vid='+this.vid+''
                                    sessionStorage.setItem('vxPhone',this.from1.phone)
                                }else{
                                    sessionStorage.setItem('logo','0')
                                    sessionStorage.setItem('token',data.data.Gtoken)
                                    this.vid=data.data.Vid
                                    sessionStorage.setItem('vids',this.vid)
                                    sessionStorage.setItem('vid',this.vid)
                                    let type="logo"
                                    localStorage.setItem('boss',"1")
                                    localStorage.setItem('bossvid',data.data.Vid)
                                    localStorage.setItem('bossGtoken',data.data.Gtoken)
                                    //保存登录有效期
                                    let timeLoc=new Date()
                                    localStorage.setItem('bossTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))
                                    sessionStorage.setItem('type',type)
                                    window.location.href='index.html?vid='+this.vid+'&type='+type+''
                                }
                            }else{
                                window.vant.Toast("该账号无法登陆BOSS端")
                            }
                            
                        }
                    }).catch(function (error) { 
                        console.log(error); 
                });
            }
    }  
})
</script>
</html>